package com.visikard.response;

import java.util.ArrayList;
import java.util.List;

import org.json.JSONArray;
import org.json.JSONException;

import android.util.Log;

import com.visikard.application.Constant;
import com.visikard.item.ItemRTUICoupon;

public class GetRTUICouponResponse extends BaseResponse {
	public static final int ERROR_NOT_FOUND = BaseResponse.USER_DEFINED_ERROR;

	private List<ItemRTUICoupon> listRTUICoupons;

	public List<ItemRTUICoupon> getListRTUICoupons() {
		return listRTUICoupons;
	}

	public void setRTUICoupons(List<ItemRTUICoupon> listRTUICoupons) {
		this.listRTUICoupons = listRTUICoupons;
	}

	@Override
	public void extractDataFromServer(String response) throws JSONException {
		super.extractDataFromServer(response);

		if (errorCode == SUCCESS) {
			JSONArray jsArr = getDataJArray(response);
			ArrayList<ItemRTUICoupon> coupons = new ArrayList<ItemRTUICoupon>();
			for (int i = 0; i < jsArr.length(); i++) {
				ItemRTUICoupon item = new ItemRTUICoupon(jsArr.getJSONObject(i));
				coupons.add(item);
			}
			listRTUICoupons = coupons;
		}
		else if (response != null && !response.isEmpty() && response.equals("Not Found")) {
			Log.e(Constant.LOG_TAG, "getGiftKardList: " + "Not Found!!!");
			errorCode = GetRTUICouponResponse.ERROR_NOT_FOUND;
			errorMsg = "Not Found";
		}
	}

}
